package mapreduce.phonenum;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MyReducer extends Reducer<Text,Bean,Text,Bean> {
    private final Bean outV = new Bean();
    @Override
    protected void reduce(Text key, Iterable<Bean> values, Reducer<Text, Bean, Text, Bean>.Context context) throws IOException, InterruptedException {
        long totalUp = 0L;
        long totalDown = 0L;
        for (Bean value : values) {
            totalUp+=value.getUpFlow();
            totalDown+=value.getDownFlow();
        }
        outV.setUpFlow(totalUp);
        outV.setDownFlow(totalDown);
        outV.setSumFlow();

        context.write(key,outV);
    }
}
